package ${serviceImplPackageName};

import cn.kawins.mybatis.base.BaseServiceImpl;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Collection;

import ${mapperPackageName}.${mapperName};
import ${voPackageName}.${voName};
import ${dtoPackageName}.${dtoName};
import ${entityPackageName}.${entityName};
import ${servicePackageName}.${serviceName};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import com.github.pagehelper.IPage;
import com.github.pagehelper.PageInfo;
import java.util.ArrayList;
import ${convertPackageName}.${convertName};
/**
* @Description: ${serviceName}实现类
* @author ${authorName}
* @date ${currentTime}
*/
@Service
@AllArgsConstructor
public class ${serviceImplName} extends BaseServiceImpl<${entityName}> implements ${serviceName} {
        private final ${mapperName} ${mapperName?uncap_first};

        @Override
        public PageInfo<${voName}> page(${dtoName} query) {
                List<${entityName}> list = this.pageList(getWrapper(query),query.getPageNum(),query.getPageSize());

                List<${voName}> voList=${convertName}.INSTANCE.convertToVOList(list);

                PageInfo<AssessTaskInfoVo> pageInfo=new PageInfo<${voName}>(voList);
                pageInfo.setPageNum(query.getPageNum());
                pageInfo.setPageSize(query.getPageSize());
                return pageInfo;
        }

        private Example getWrapper(${dtoName} query){
                Example example = new Example(${entityName}.class);
                <#list afterExcludeProps as column>
                <#if column.columnName != "id">
                if (query.get${column.caseAttrName?cap_first}()!=null) {
                   example.createCriteria().andEqualTo("${column.caseAttrName}", query.get${column.caseAttrName?cap_first}());
                }
                </#if>
                </#list>

                return example;
        }

        @Override
        public List<${voName}> listByDTO(${dtoName} query) {
                Example queryWrapper=getWrapper(query);
                List<${entityName}> entityList=this.selectByExample(queryWrapper);;
                return ${convertName}.INSTANCE.convertToVOList(entityList);
        }

        @Override
        @Transactional(rollbackFor = Exception.class)
        public ${entityName} save(${voName} vo) {
                ${entityName} entity = ${convertName}.INSTANCE.convert(vo);
                this.insert(entity);
                return entity;
        }

        @Override
        @Transactional(rollbackFor = Exception.class)
        public ${entityName} update(${voName} vo) {
                ${entityName} entity = ${convertName}.INSTANCE.convert(vo);
                this.updateById(entity);
                return entity;
        }

        @Override
        @Transactional(rollbackFor = Exception.class)
        public boolean saveBatch(Collection<${entityName}> entityList) {
                 return this.insertList(new ArrayList<>(entityList))>0;
        }

        @Override
        @Transactional(rollbackFor = Exception.class)
        public void delete(List<Long> idList) {
                deleteByIds(idList);
        }

}